//
//  MainViewController.swift
//  SinaWeibo25
//
//  Created by David on 16/3/5.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit


class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabbar = MainTabBar()
        //KVC 给对象提供类似字典的的方式 访问对象的属性
        //系统的tabbar 是只读属性 不能够直接操作
        print(tabBar.classForCoder)
        setValue(mainTabbar, forKey: "tabBar")
        print(tabBar.classForCoder)
        //添加所有的子视图控制器
        addChildViewControllers()
    }
    
    
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    
    //MARK: 添加子视图控制器
    private func addChildViewController(vc: UIViewController,title: String, imageName: String) {
        //设置title
        //vc.tabBarItem.title = title
        //vc.navigationItem.title = title
        vc.title = title
        vc.tabBarItem.title = title
        
        //设置字体
        //   vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        //设置 tintColor
        tabBar.tintColor = UIColor.orangeColor()
        
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //设置选中图片
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        let nav = UINavigationController(rootViewController: vc)
//        vc.navigationItem.title = "哈哈哈哈"
        addChildViewController(nav)
   
    }

}
